using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace shfa.snomtastic.data
{
    public partial class SqlDataProvider
    {

        public Guid InsertUser(Guid groupId, string userName, string password, DateTime passwordUpdate, DateTime passwordUpdateAD, DateTime createdDate, DateTime updatedDate, DateTime lastAccessDate)
		{
            return new Guid(Convert.ToString(SqlHelper.ExecuteScalar(ConnectionString, "sp_UserInsert", GetNull(groupId), userName, password, GetNull(passwordUpdate), GetNull(passwordUpdateAD), GetNull(createdDate), GetNull(updatedDate), GetNull(lastAccessDate))));
		}

        public int UpdateUser(Guid userId, Guid groupId, string userName, string password, DateTime passwordUpdate, DateTime passwordUpdateAD, DateTime createdDate, DateTime updatedDate, DateTime lastAccessDate)
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_UserUpdate", GetNull(userId), GetNull(groupId), userName, password, GetNull(passwordUpdate), GetNull(passwordUpdateAD), GetNull(createdDate), GetNull(updatedDate), GetNull(lastAccessDate)));
		}

        public int DeleteUser(Guid userId) 
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_UserDelete", userId));
		}

        public DataRow SelectUser(Guid userId) 
        {    
			DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_UserSelect", userId);
            if (ds.Tables.Count > 0)
                if (ds.Tables[0].Rows.Count > 0)
                    return ds.Tables[0].Rows[0];

            return null;
		}

		public DataTable SelectUsers() 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_UserSelectAll").Tables[0];
        }

		public DataTable SelectUsersByGroup(Guid groupId) 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_UserSelectByGroup", groupId).Tables[0];
        }

    }

}
